<template>
  <div>
    <!--日历组件-->
      <div class="calendar" v-show="g_caledar == undefined">
        <div class="calendar-tools">
          <span class="calendar-prev" @click="prev">
                <svg width="20" height="20" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <g class="transform-group">
                    <g transform="scale(0.015625, 0.015625)">
                        <path d="M671.968 912c-12.288 0-24.576-4.672-33.952-14.048L286.048 545.984c-18.752-18.72-18.752-49.12 0-67.872l351.968-352c18.752-18.752 49.12-18.752 67.872 0 18.752 18.72 18.752 49.12 0 67.872l-318.016 318.048 318.016 318.016c18.752 18.752 18.752 49.12 0 67.872C696.544 907.328 684.256 912 671.968 912z" fill="#5e7a88"></path>
                    </g>
                </g>
                </svg>
            </span>
            <span class="calendar-next"  @click="next">
                <svg width="20" height="20" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <g class="transform-group">
                    <g transform="scale(0.015625, 0.015625)">
                        <path d="M761.056 532.128c0.512-0.992 1.344-1.824 1.792-2.848 8.8-18.304 5.92-40.704-9.664-55.424L399.936 139.744c-19.264-18.208-49.632-17.344-67.872 1.888-18.208 19.264-17.376 49.632 1.888 67.872l316.96 299.84-315.712 304.288c-19.072 18.4-19.648 48.768-1.248 67.872 9.408 9.792 21.984 14.688 34.56 14.688 12 0 24-4.48 33.312-13.44l350.048-337.376c0.672-0.672 0.928-1.6 1.6-2.304 0.512-0.48 1.056-0.832 1.568-1.344C757.76 538.88 759.2 535.392 761.056 532.128z" fill="#5e7a88"></path>
                    </g>
                </g>
                </svg>
            </span>
            <div class="calendar-info" @click.stop="changeYear">
                <div class="year">{{year}}</div>
                <!-- {{monthString}} -->

                <div class="month">
                    <div class="month-inner" :style="{'top':-(this.month*20)+'px'}">
                        <span v-for="m in months">{{m}}</span>
                    </div>
                </div>
            </div>
        </div>
        <table cellpadding="5">
        <thead>
            <tr>
                <td v-for="week in weeks" class="week">{{week}}</td>
            </tr>
        </thead>
        <tbody>
        <tr v-for="(day,k1) in days" style="{'animation-delay',(k1*30)+'ms'}">
            <td v-for="(child,k2) in day" :class="{'selected':child.selected,'disabled':child.disabled || !array[child.day]}" @click="select(k1,k2,$event,child,datemoney[child.day],childmoney[child.day])">
                <span :class="{'red':k2===0||k2===6||((child.isLunarFestival||child.isGregorianFestival) && lunar)}">{{child.day}}</span>
                <span v-if="child.disabled != true && datemoney[child.day] != 0">💰{{datemoney[child.day]}}</span>
                <div class="text" v-if="child.eventName!==undefined">{{child.eventName}}</div>
                <div class="text" :class="{'isLunarFestival':child.isLunarFestival,'isGregorianFestival':child.isGregorianFestival}" v-if="lunar">{{child.lunar}}</div>
            </td>
        </tr>
        </tbody>
        </table>

        <div class="calendar-years" :class="{'show':yearsShow}">
            <span v-for="y in years" @click.stop="selectYear(y)" :class="{'active':y===year}">{{y}}</span>
        </div>
      </div>

      <!--选择用户组件-->
      <div class="">
        <div class="v_mod trip_actions_mod">
          <ul class="trip_actions">
            <li>
              <div class="type"><span>成人</span><span class="trip_price js_adult_price">¥{{g_manPrice}}/人</span></div>
              <div class="pkg_room_num js_adult">
                  <yd-spinner v-model="spinner1"></yd-spinner>
              </div>
            </li>
            <li>
              <div class="type"><span>儿童</span><span class="grey"></span><span class="trip_price js_children_price">¥{{g_childPrice}}/人</span></div>
              <div class="pkg_room_num js_children">
                <yd-spinner min="0" v-model="spinner2"></yd-spinner>
              </div>
            </li>
            <li class="js_infant" data-sk-eid="hy_ctr_baby" data-sk-edata="{&quot;status&quot;:false}">
              <!-- <div class="infant_box"><i class=""></i>
                <p><span>携带婴儿</span><span class="age">0-2岁</span></p>
                <p class="infant_tips hidden">订单提交后，工作人员会与您联系确认婴儿出行信息与价格</p>
              </div> -->
              <div class="infant_box">
                <yd-flexbox>
                  <div>
                    <yd-checkbox v-model="checkbox1" size="15" color="#ff7d13" style="font-size:13px;">携带婴儿</yd-checkbox>
                  </div>
                  <div>
                    0-2岁
                  </div>
                </yd-flexbox>
                <p class="infant_tips" v-if="checkbox1 == true">订单提交后，工作人员会与您联系确认婴儿出行信息与价格</p>
              </div>
            </li>
            <li>
              <div class="set_num_tip">
                <p>最少1人起订，年龄2-12周岁，不占床，含机票及税、旅游车位费、导游服务费、半餐费（早餐不含）。其余当地产生一切费用自理（桂林阳朔当地的景点游览会根据儿童身高按不同比例收费，此部分费用由家长在当地根据景区规定现付）。如果行程中有遇龙河漂流，儿童高度达到1m（含1m）必须购买成人票。，成人+儿童最多支持9人，<span class="tips">*以上价格均为起价</span></p>
              </div>
            </li>
          </ul></br></br></br>
        </div>
      </div>

      <!--底部组件-->
      <div class="">
        <yd-tabbar fixed bgcolor="#fff" class="mod_foot_acitons" v-bind:style="styleBot">
          <div class="foot_order_info foot_order_info2 js_concat_pm" style="display:none"><span class="item valet_order_btn1 js_concat_pm_tel"><a href="###">联系产品经理</a></span></div>
          <div class="js_submit_box foot_order_info foot_order_info2">
            <span class="item item_col1">
              <i class="loading_ico js-loading-step1" style="margin-top: 8px; display: none;"></i> 
              <span class="js-price-step1" data-sk-eid="hy_ctr_costdetail">
                <span class="ft_sum_name">总额：</span>
                <span class="price"><dfn>¥</dfn>
                  <span>{{(spinner1 * g_manPrice) + (spinner2 * g_childPrice)}}</span>
                </span>
              </span> 
              <span class="js-not-enough" style="display: none;">
                <span class="ft_sum_name">总额：待确认</span>
              </span>
            </span> 
            <span class="item item_col3 js_btn_next js_submit_1 js_submit_4" data-sk-eid="hy_ctr_tap_next">
              <a href="javascript:;" class="btn_link5" id="lyx_jxyd" @click="gogo()">继续预订</a>
            </span>	
          </div>
        </yd-tabbar>
      </div>
  </div>
</template>

<script>
import calendar from 'hdc/calendar';

export default {
  name: 'boutiquelinebuy',
  props: {
    value: {
      type: Array,
      default: function() {
        return [];
      }
    },
    begin: {
      type: Array,
      default: function() {
        return [];
      }
    },
    end: {
      type: Array,
      default: function() {
        return [];
      }
    },
    range: {
      type: Boolean,
      default: false
    },
    zero: {
      type: Boolean,
      default: false
    },
    lunar: {
      type: Boolean,
      default: false
    },
    weeks: {
      type: Array,
      default: function() {
        return window.navigator.language.toLowerCase() === 'zh-cn'
          ? ['日', '一', '二', '三', '四', '五', '六']
          : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
      }
    },
    months: {
      type: Array,
      default: function() {
        return window.navigator.language.toLowerCase() === 'zh-cn'
        ? ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'] : ['January',
          'February',
          'March',
          'April',
          'May',
          'June',
          'July',
          'August',
          'September',
          'October',
          'November',
          'December'
        ];
      }
    },
    events: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      styleBot: {
        'margin-bottom': '0'
      },
      checkbox1: false,
      years: [],
      yearsShow: false,
      year: 0,
      month: 0,
      day: 0,
      days: [],
      today: [],
      festival: {
        lunar: {
          '1-1': '春节',
          '1-15': '元宵节',
          '2-2': '龙头节',
          '5-5': '端午节',
          '7-7': '七夕节',
          '7-15': '中元节',
          '8-15': '中秋节',
          '9-9': '重阳节',
          '10-1': '寒衣节',
          '10-15': '下元节',
          '12-8': '腊八节',
          '12-23': '祭灶节'
        },
        gregorian: {
          '1-1': '元旦',
          '2-14': '情人节',
          '3-8': '妇女节',
          '3-12': '植树节',
          '4-5': '清明节',
          '5-1': '劳动节',
          '5-4': '青年节',
          '6-1': '儿童节',
          '7-1': '建党节',
          '8-1': '建军节',
          '9-10': '教师节',
          '10-1': '国庆节',
          '12-24': '平安夜',
          '12-25': '圣诞节'
        }
      },
      rangeBegin: [],
      rangeEnd: [],
      flag: '0',
      product_info: this.$route.query.product_info,
      g_totalMoney: 0, // 总钱数
      g_totalCredits: 0, // 总人数
      g_manNum: this.$route.query.manNum, // 成人数量
      g_childNum: this.$route.query.childNum, // 儿童数量
      g_caledar: this.$route.query.datetime, // 选中日期
      g_manPrice: this.$route.query.manPrice || 0, // 成人价格
      g_childPrice: this.$route.query.childPrice || 0, // 儿童价格
      total_credits: 0,
      max_credits: 0,
      product_id: this.$route.query.id,
      spinner1: 0,
      spinner2: 0,
      selectnextdate: '', // 选中传到下页的日期
      bookdatearr: [],
      bookdatestr: '',
      array: [],
      datemoney: [],
      bookdatemoney: [],
      bookchildmoney: [],
      childmoney: [],
      selectMonthArr: [] // 可选日期月份
    }
  },
  watch: {
    events() {
      this.render(this.year, this.month);
    }
  },
  mounted() {
    var ua = window.navigator.userAgent.toLowerCase()
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
      this.styleBot = {
        'margin-bottom': '0'
      };
    } else {
      this.styleBot = {
        'margin-bottom': '1rem'
      };
    }
    console.log('传过来的选择的出行日期', this.g_caledar);
    console.log(this.$route.query.product_info);
    this.g_totalMoney = this.g_manPrice * this.spinner1 + this.g_childPrice * this.spinner2;
    // 显示传过来的日期的价格(没选默认为0)
    this.init();
    // 获取当前日期
    this.date = new Date();
    // 初始化本地信息
    this.getLineTime((this.month + 1));
    console.log('1111111');
    console.log(this.days);
    console.log(this.g_caledar);
    // 传过来的日期设置为已选择
    if (this.g_caledar !== undefined) {
      this.days.forEach(element => {
        for (var i = 0; i < element.length; i++) {
          if (element[i].day === parseInt(this.g_caledar.split('-')[2]) && !element[i].disabled) {
            console.log(element[i].day);
            element[i].selected = true;
            console.log(element[i]);
          }
        }
      });
    }
  },
  methods: {
    gogo() {
      this.g_manNum = this.spinner1;
      this.g_childNum = this.spinner2;
      this.g_totalMoney = this.g_manNum * this.g_manPrice + this.g_childNum * this.g_childPrice;
      this.g_totalCredits = this.spinner1 + this.spinner2;
      this.$router.push({path: 'boutiquelinestep1', query: {id: this.product_id, 'totalMoney': this.g_totalMoney, 'datetime': this.g_caledar, 'manNum': this.g_manNum, 'childNum': this.g_childNum, 'totalCredits': this.g_totalCredits, 'product_info': this.product_info}});
    },
    // 团期信息
    getLineTime(month) {
      this.hdAjax({
        url: this.API.lineSelectDate,
        data: {
          product_id: this.product_id
        },
        success: (resultData) => {
          console.log('入参' + month);
          this.selectMonthArr.length = 0;
          this.bookdatearr.length = 0;
          resultData.data.results.forEach(element => {
            // 将可预订的团期的日塞到一个数组里面
            this.bookdatearr.push(element.tour_date.split('-')[2]);
            // 将可预订的团期的月塞到一个数组里面
            element['selectMonth'] = element.tour_date.split('-')[1];
            this.selectMonthArr.push(element);
            // 成人儿童价格
            this.bookdatemoney.push(element.adult_sale_price);
            this.bookchildmoney.push(element.children_sale_price);
          });
          // 循环加月份后的团期信息
          var map = {};
          var dest = [];
          for (var i = 0; i < this.selectMonthArr.length; i++) {
            var ai = this.selectMonthArr[i];
            if (!map[ai.selectMonth]) {
              dest.push({
                selectMonth: ai.selectMonth,
                data: [ai]
              });
              map[ai.selectMonth] = ai;
            } else {
              for (var q = 0; q < dest.length; q++) {
                var dj = dest[q];
                if (dj.selectMonth === ai.selectMonth) {
                  dj.data.push(ai);
                  break;
                }
              }
            }
          }
          console.log('重组数组');
          console.log(dest);
          console.log((this.month + 1));
          var nowMonthArr = [];
          dest.forEach(element => {
            console.log(element.selectMonth);
            if (parseInt(element.selectMonth) === month) {
              // nowMonthArr = element.data;
              element.data.forEach(element => {
                nowMonthArr.push(element.tour_date.split('-')[2]);
              });
            }
          });
          console.log('当月日期数组');
          console.log(nowMonthArr);
          console.log(this.bookdatearr);
          // 循环31遍创建一个数组
          for (var k = 0; k <= 31; k++) {
            this.array[k] = false;
            this.datemoney[k] = '';
            this.childmoney[k] = '';
          }
          console.log(this.array);
          // 每月的日期数组循环作为日历数组的小标,设置为选中状态
          for (var j = 0; j < nowMonthArr.length; j++) {
            if (nowMonthArr[j].indexOf('0') === 0) {
              nowMonthArr[j] = nowMonthArr[j].substr(1, 1);
            }
            this.array[nowMonthArr[j]] = true;
            this.datemoney[nowMonthArr[j]] = this.bookdatemoney[j];
            this.childmoney[nowMonthArr[j]] = this.bookchildmoney[j];
          }
          console.log('array');
          console.log(this.array);
          console.log(this.datemoney);
        }
      });
    },
    // 初始化一些东西
    init() {
      let now = new Date();
      // 没有默认值
      this.year = now.getFullYear();
      this.month = now.getMonth();
      this.day = now.getDate();
      // this.xmday = now.getDate();
      // console.log('当前日期' + this.xmday);
      if (this.value.length > 0) {
        if (this.range) {
          this.year = parseInt(this.value[0][0]);
          this.month = parseInt(this.value[0][1]) - 1;
          this.day = parseInt(this.value[0][2]);
          let year2 = parseInt(this.value[1][0]);
          let month2 = parseInt(this.value[1][1]) - 1;
          let day2 = parseInt(this.value[1][2]);
          this.rangeBegin = [this.year, this.month, this.day];
          this.rangeEnd = [year2, month2, day2];
          // console.log(this.month,this.rangeBegin,this.rangeEnd)
        } else {
          this.year = parseInt(this.value[0]);
          this.month = parseInt(this.value[1]) - 1;
          this.day = parseInt(this.value[2]);
        }
      }
      this.render(this.year, this.month);
    },
    // 渲染日期
    render(y, m) {
      let firstDayOfMonth = new Date(y, m, 1).getDay(); // 当月第一天
      let lastDateOfMonth = new Date(y, m + 1, 0).getDate(); // 当月最后一天
      console.log('当月最后一天' + lastDateOfMonth);
      for (i = 1; i <= lastDateOfMonth; i++) {
        let options = Object.assign(
          { day: i, disabled: true },
          this.getLunarInfo(this.year, this.month + 1, i),
          this.getEvents(this.year, this.month + 1, i)
        );
        if (options.day === 29) {
          this.flag = options.day;
        }
      }
      let lastDayOfLastMonth = new Date(y, m, 0).getDate(); // 最后一月的最后一天
      this.year = y;
      let seletSplit = this.value;
      let i;
      let line = 0;
      let temp = [];
      let nextMonthPushDays = 1;
      for (i = 1; i <= lastDateOfMonth; i++) {
        let day = new Date(y, m, i).getDay(); // 返回星期几（0～6）
        let k;
        // 第一行
        if (day === 0) {
          temp[line] = [];
        } else if (i === 1) {
          temp[line] = [];
          k = lastDayOfLastMonth - firstDayOfMonth + 1;
          for (let j = 0; j < firstDayOfMonth; j++) {
            // console.log('第一行',lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              Object.assign(
                { day: k, disabled: true },
                this.getLunarInfo(
                  this.computedPrevYear(),
                  this.computedPrevMonth(true),
                  k
                ),
                this.getEvents(
                  this.computedPrevYear(),
                  this.computedPrevMonth(true),
                  k
                )
              )
            );
            k++;
          }
        }

        // 范围
        if (this.range) {
          // console.log('日期范围',this.getLunarInfo(this.year,this.month+1,i))
          let options = Object.assign(
            { day: i },
            this.getLunarInfo(this.year, this.month + 1, i),
            this.getEvents(this.year, this.month + 1, i)
          );
          if (this.rangeBegin.length > 0) {
            let beginTime = Number(
              new Date(
                this.rangeBegin[0],
                this.rangeBegin[1],
                this.rangeBegin[2]
              )
            );
            let endTime = Number(
              new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2])
            );
            let stepTime = Number(new Date(this.year, this.month, i));
            if (beginTime <= stepTime && endTime >= stepTime) {
              alert('开始截止');
              options.selected = true;
            }
          }
          if (this.begin.length > 0) {
            let beginTime = Number(
              new Date(
                parseInt(this.begin[0]),
                parseInt(this.begin[1]) - 1,
                parseInt(this.begin[2])
              )
            );
            if (beginTime > Number(new Date(this.year, this.month, i))) {
              alert('开始时间打');
              options.disabled = true;
            }
          }
          if (this.end.length > 0) {
            let endTime = Number(
              new Date(
                parseInt(this.end[0]),
                parseInt(this.end[1]) - 1,
                parseInt(this.end[2])
              )
            );
            if (endTime < Number(new Date(this.year, this.month, i))) {
              options.disabled = true;
            }
          }
          temp[line].push(options);
        } else {
          // console.log(this.lunar(this.year,this.month,i));
          // 单选模式
          let chk = new Date();
          let chkY = chk.getFullYear();
          let chkM = chk.getMonth();
          // 匹配上次选中的日期
          if (
            parseInt(seletSplit[0]) === this.year &&
            parseInt(seletSplit[1]) - 1 === this.month &&
            parseInt(seletSplit[2]) === i
          ) {
            // console.log('匹配上次选中的日期',lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              Object.assign(
                { day: i, selected: true },
                this.getLunarInfo(this.year, this.month + 1, i),
                this.getEvents(this.year, this.month + 1, i)
              )
            );
            this.today = [line, temp[line].length - 1];
          } else if (
            chkY === this.year &&
            chkM === this.month &&
            i === this.day &&
            this.value === ''
          ) {
            // 没有默认值的时候显示选中今天日期
            // console.log('今天',lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              Object.assign(
                { day: i, selected: true },
                this.getLunarInfo(this.year, this.month + 1, i),
                this.getEvents(this.year, this.month + 1, i)
              )
            );
            this.today = [line, temp[line].length - 1];
          } else {
            // 普通日期
            // console.log('设置可选范围',i,lunarYear,lunarMonth,lunarValue,lunarInfo)
            let options = Object.assign(
              { day: i, selected: false },
              this.getLunarInfo(this.year, this.month + 1, i),
              this.getEvents(this.year, this.month + 1, i)
            );
            if (this.begin.length > 0) {
              let beginTime = Number(
                new Date(
                  parseInt(this.begin[0]),
                  parseInt(this.begin[1]) - 1,
                  parseInt(this.begin[2])
                )
              );
              if (beginTime > Number(new Date(this.year, this.month, i))) {
                options.disabled = true;
              }
            }
            if (this.end.length > 0) {
              let endTime = Number(
                new Date(
                  parseInt(this.end[0]),
                  parseInt(this.end[1]) - 1,
                  parseInt(this.end[2])
                )
              );
              if (endTime < Number(new Date(this.year, this.month, i))) {
                options.disabled = true;
              }
            }
            temp[line].push(options);
          }
        }
        // 到周六换行
        if (day === 6 && i < lastDateOfMonth) {
          line++;
        } else if (i === lastDateOfMonth) {
          // line++
          let k = 1;
          for (let d = day; d < 6; d++) {
            // console.log(this.computedNextYear()+'-'+this.computedNextMonth(true)+'-'+k)
            temp[line].push(
              Object.assign(
                { day: k, disabled: true },
                this.getLunarInfo(
                  this.computedNextYear(),
                  this.computedNextMonth(true),
                  k
                ),
                this.getEvents(
                  this.computedNextYear(),
                  this.computedNextMonth(true),
                  k
                )
              )
            );
            k++;
          }
          // 下个月除了补充的前几天开始的日期
          nextMonthPushDays = k;
        }
      } // end for
      // console.log(this.year+'/'+this.month+'/'+this.day+':'+line)
      // 补充第六行让视觉稳定
      if (line <= 5 && nextMonthPushDays > 0) {
        // console.log({nextMonthPushDays:nextMonthPushDays,line:line})
        for (let i = line + 1; i <= 5; i++) {
          temp[i] = [];
          let start = nextMonthPushDays + (i - line - 1) * 7;
          for (let d = start; d <= start + 6; d++) {
            temp[i].push(
              Object.assign(
                { day: d, disabled: true },
                this.getLunarInfo(
                  this.computedNextYear(),
                  this.computedNextMonth(true),
                  d
                ),
                this.getEvents(
                  this.computedNextYear(),
                  this.computedNextMonth(true),
                  d
                )
              )
            );
          }
        }
      }
      this.days = temp;
    },
    computedPrevYear() {
      let value = this.year;
      if (this.month - 1 < 0) {
        value--;
      }
      return value;
    },
    computedPrevMonth(isString) {
      let value = this.month;
      if (this.month - 1 < 0) {
        value = 11;
      } else {
        value--;
      }
      // 用于显示目的（一般月份是从0开始的）
      if (isString) {
        return value + 1;
      }
      return value;
    },
    computedNextYear() {
      let value = this.year;
      if (this.month + 1 > 11) {
        value++;
      }
      return value;
    },
    computedNextMonth(isString) {
      let value = this.month;
      if (this.month + 1 > 11) {
        value = 0;
      } else {
        value++;
      }
      // 用于显示目的（一般月份是从0开始的）
      if (isString) {
        return value + 1;
      }
      return value;
    },
    // 获取农历信息
    getLunarInfo(y, m, d) {
      let lunarInfo = calendar.solar2lunar(y, m, d);
      let lunarValue = lunarInfo.IDayCn;
      // console.log(lunarInfo)
      let isLunarFestival = false;
      let isGregorianFestival = false;
      if (
        this.festival.lunar[lunarInfo.lMonth + '-' + lunarInfo.lDay] !==
        undefined
      ) {
        lunarValue = this.festival.lunar[lunarInfo.lMonth + '-' + lunarInfo.lDay];
        isLunarFestival = true;
      } else if (this.festival.gregorian[m + '-' + d] !== undefined) {
        lunarValue = this.festival.gregorian[m + '-' + d];
        isGregorianFestival = true;
      }
      return {
        lunar: lunarValue,
        isLunarFestival: isLunarFestival,
        isGregorianFestival: isGregorianFestival
      };
    },
    // 获取自定义事件
    getEvents(y, m, d) {
      if (Object.keys(this.events).length === 0) return false;
      if (this.events[y + '-' + m + '-' + d] !== undefined) {
        return {
          eventName: this.events[y + '-' + m + '-' + d]
        };
      }
      return {};
    },
    // 上月
    prev(e) {
      e.stopPropagation();
      if (this.month === 0) {
        this.month = 11;
        this.year = parseInt(this.year) - 1;
      } else {
        this.month = parseInt(this.month) - 1;
      }
      this.render(this.year, this.month);
      // 获取可选日期
      this.getLineTime((this.month + 1));
    },
    //  下月
    next(e) {
      e.stopPropagation();
      if (this.month === 11) {
        this.month = 0;
        this.year = parseInt(this.year) + 1;
      } else {
        this.month = parseInt(this.month) + 1;
      }
      this.render(this.year, this.month);
      console.log('next' + this.month);
      // 获取可选日期
      this.getLineTime((this.month + 1));
    },
    // 选中日期
    select(k1, k2, e, date, adultmoney, childmoney) {
      this.g_manPrice = adultmoney;
      this.g_childPrice = childmoney;
      // this.selecteddate['adultsaleprice'] = adultmoney;
      // this.selecteddate['childsaleprice'] = childmoney;
      this.selectnextdate = date.day;
      this.g_caledar = [this.year, this.month + 1, this.selectnextdate].join('-');
      console.log('选中的日期' + this.g_caledar, this.year, this.month);
      if (e !== undefined) e.stopPropagation();
      // 日期范围
      if (this.range) {
        if (this.rangeBegin.length === 0 || this.rangeEndTemp !== 0) {
          this.rangeBegin = [this.year, this.month, this.days[k1][k2].day];
          this.rangeBeginTemp = this.rangeBegin;
          this.rangeEnd = [this.year, this.month, this.days[k1][k2].day];
          this.rangeEndTemp = 0;
        } else {
          this.rangeEnd = [this.year, this.month, this.days[k1][k2].day];
          this.rangeEndTemp = 1;
          // 判断结束日期小于开始日期则自动颠倒过来
          if (
            +new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2]) <
            +new Date(
              this.rangeBegin[0],
              this.rangeBegin[1],
              this.rangeBegin[2]
            )
          ) {
            this.rangeBegin = this.rangeEnd;
            this.rangeEnd = this.rangeBeginTemp;
          }
          // 小于10左边打补丁
          let begin = [];
          let end = [];
          if (this.zero) {
            this.rangeBegin.forEach((v, k) => {
              if (k === 1) v = v + 1;
              begin.push(this.zeroPad(v));
            });
            this.rangeEnd.forEach((v, k) => {
              if (k === 1) v = v + 1;
              end.push(this.zeroPad(v));
            });
          } else {
            begin = this.rangeBegin;
            end = this.rangeEnd;
            begin[1]++;
            end[1]++;
          }
          // console.log('选中日期',begin,end)
          this.$emit('select', begin, end);
        }
        this.render(this.year, this.month);
      } else {
        // 取消上次选中
        console.log('取消上次选中');
        console.log(this.today);
        if (this.today.length >= 0) {
          this.days.forEach(v => {
            v.forEach(vv => {
              console.log(vv.selected);
              vv.selected = false;
            });
          });
        }
        // 设置当前选中天
        console.log(k1, k2);
        this.days[k1][k2].selected = true;
        this.day = this.days[k1][k2].day;
        this.today = [k1, k2];
        this.$emit('select', [
          this.year,
          this.zero ? this.zeroPad(this.month + 1) : this.month + 1,
          this.zero
            ? this.zeroPad(this.days[k1][k2].day)
            : this.days[k1][k2].day
        ]);
      }
    },
    // 日期补零
    zeroPad(n) {
      return String(n < 10 ? '0' + n : n);
    },
    // 年份弹出框
    changeYear() {
      if (this.yearsShow) {
        this.yearsShow = false;
        return false;
      }
      this.yearsShow = true;
      this.years = [];
      for (let i = ~~this.year - 10; i < ~~this.year + 10; i++) {
        this.years.push(i);
      }
    },
    // 选择年份
    selectYear(value) {
      this.yearsShow = false;
      this.year = value;
      this.render(this.year, this.month);
    }

  }
}
</script>

<style scoped>
body{
	color:#666666; 
	font-size:14px; 
	font-family:"微软雅黑"; 
	background-color:#f5f5f5 ; 
	height:100%; 
	overflow-y:scroll;
}
a{ 
	text-decoration:none; 
	outline:none;
}
img{
	border:none;
}
ul{
	list-style:none;
}
.clearfix:after{
	content:"."; 
	display:block; 
	height:0; 
	clear:both; 
	overflow:hidden;
}
.clearfix{
	zoom:1;
}
/*日历*/
.calendar {
  margin: auto;
  width: 100%;
  min-width: 300px;
  background: #fff;
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'STHeiti', 'Microsoft YaHei',
    'WenQuanYi Micro Hei', sans-serif;
  user-select: none;
}
.calendar-tools {
  height: 40px;
  font-size: 20px;
  line-height: 40px;
  color: #5e7a88;
}
.calendar-tools span {
  cursor: pointer;
}
.calendar-prev {
  width: 14.28571429%;
  float: left;
  text-align: center;
}
.calendar-info {
  padding-top: 3px;
  font-size: 16px;
  line-height: 1.3;
  text-align: center;
}
.calendar-info > div.month {
  margin: auto;
  height: 20px;
  width: 100px;
  text-align: center;
  color: #5e7a88;
  overflow: hidden;
  position: relative;
}
.calendar-info > div.month .month-inner {
  position: absolute;
  left: 0;
  top: 0;
  height: 240px;
  transition: top 0.5s cubic-bezier(0.075, 0.82, 0.165, 1);
}
.calendar-info > div.month .month-inner > span {
  display: block;
  font-size: 14px;
  height: 20px;
  width: 100px;
  overflow: hidden;
  text-align: center;
}
.calendar-info > div.year {
  font-size: 10px;
  line-height: 1;
  color: #999;
}
.calendar-next {
  width: 14.28571429%;
  float: right;
  text-align: center;
}

.calendar table {
  clear: both;
  width: 100%;
  margin-bottom: 10px;
  border-collapse: collapse;
  color: #444444;
}
.calendar td {
  margin: 2px !important;
  padding: 0px 0;
  width: 14.28571429%;
  height: 44px;
  text-align: center;
  vertical-align: middle;
  font-size: 14px;
  line-height: 125%;
  cursor: pointer;
  position: relative;
  vertical-align: top;
}
.calendar td.week {
  font-size: 10px;
  pointer-events: none !important;
  cursor: default !important;
}
.calendar td.disabled {
  color: #ccc;
  pointer-events: none !important;
  cursor: default !important;
}
.calendar td.disabled div {
  color: #ccc;
}
.calendar td span {
  display: block;
  max-width: 40px;
  height: 26px;
  font-size: 16px;
  line-height: 26px;
  margin: 0px auto;
  border-radius: 20px;
}
.calendar td:not(.selected) span:not(.red):hover {
  background: #f3f8fa;
  color: #444;
}
.calendar td:not(.selected) span.red:hover {
  background: #f9efef;
}
.calendar td:not(.disabled) span.red {
  color: #ea6151;
}
.calendar td.selected span {
  background-color: #5e7a88;
  color: #fff;
}
.calendar td .text {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  text-align: center;

  padding: 2px;
  font-size: 8px;
  line-height: 1.2;
  color: #444;
}
.calendar td .isGregorianFestival,
.calendar td .isLunarFestival {
  color: #ea6151;
}
.calendar td.selected span.red {
  background-color: #ea6151;
  color: #fff;
}
.calendar td.selected span.red:hover {
  background-color: #ea6151;
  color: #fff;
}
.calendar thead td {
  text-transform: uppercase;
  height: 30px;
  vertical-align: middle;
}
.calendar-button {
  text-align: center;
}
.calendar-button span {
  cursor: pointer;
  display: inline-block;
  min-height: 1em;
  min-width: 5em;
  vertical-align: baseline;
  background: #5e7a88;
  color: #fff;
  margin: 0 0.25em 0 0;
  padding: 0.6em 2em;
  font-size: 1em;
  line-height: 1em;
  text-align: center;
  border-radius: 0.3em;
}
.calendar-button span.cancel {
  background: #efefef;
  color: #666;
}
.calendar-years {
  position: absolute;
  left: 0px;
  top: 60px;
  right: 0px;
  bottom: 0px;
  background: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  overflow: auto;
  transition: all 0.5s cubic-bezier(0.075, 0.82, 0.165, 1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}
.calendar-years.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0px);
}
.calendar-years > span {
  margin: 1px 5px;
  display: inline-block;
  width: 60px;
  line-height: 30px;
  border-radius: 20px;
  text-align: center;
  border: 1px solid #fbfbfb;
  color: #999;
}
.calendar-years > span.active {
  border: 1px solid #5e7a88;
  background-color: #5e7a88;
  color: #fff;
}


/*选择用户*/
.trip_actions_mod {
    background-color: #fff;
}
.trip_actions li {
    position: relative;
    padding: 12px 0;
    margin-left: 15px;
    overflow: hidden;
}
.trip_actions li:before {
    position: absolute;
    left: 0;
    content: '';
    width: 200%;
    height: 0;
    border-bottom: 1px solid #d4d4d4;
    -webkit-transform: scale(0.5);
    -ms-transform: scale(0.5);
    -moz-transform: scale(0.5);
    transform: scale(0.5);
    bottom: 0;
    -webkit-transform-origin: left bottom;
    -ms-transform-origin: left bottom;
    -moz-transform-origin: left bottom;
    transform-origin: left bottom;
}
.trip_actions li .type {
    float: left;
}
.trip_actions .type .trip_price {
    margin-left: 10px;
    color: #ff7d13;
}
.pkg_room_num {
    position: absolute;
    right: 0;
    top: 50%;
    margin-top: -16px;
    /* width: 86px; */
    height: 28px;
    line-height: 28px;
    color: #666;
    background-color: #FFF;
    text-align: center;
    border: 1px solid #e4e4e4;
    vertical-align: middle;
    margin-right: 6px;
    border-radius: 4px;
}
.pkg_room_num i:first-child {
    left: 0;
    color: #009ee4;
    font: 400 34px/24px Arial;
    border-right: 1px solid #e4e4e4;
    border-radius: 4px 0 0 4px;
}
.pkg_room_num i:last-child {
    right: 0;
    color: #009ee4;
    border-left: 1px solid #e4e4e4;
    border-radius: 0 4px 4px 0;
}
.pkg_room_num i {
    position: absolute;
    width: 27px;
    height: 28px;
    text-align: center;
    font: 400 26px/28px Arial;
    background: 0;
}
.pkg_room_num .list_num_dec ~ .list_num {
    color: #FFF;
    background-color: #009de3;
    border-color: #009de3;
}
.pkg_room_num .list_num {
    display: inline-block;
    width: 30px;
    height: 26px;
    line-height: 26px;
    font-size: 14px;
    vertical-align: top;
    white-space: nowrap;
    overflow: hidden;
}
.infant_box {
    line-height: 18px;
    /* padding: 0 5px 0 26px; */
    position: relative;
    font-size: 12px;
}
.infant_box i {
    width: 15px;
    height: 15px;
    border: 1px solid #999;
    border-radius: 3px;
    position: absolute;
    left: 0;
    top: 0;
}
.infant_box .age {
    margin-left: 5px;
    font-size: 12px;
    color: #999;
}
.infant_box .infant_tips {
    color: #999;
}
.infant_box .cur {
    border-color: #00a1db;
    background: #00a1db;
}
.infant_box .cur:after {
    content: "";
    width: 6px;
    height: 14px;
    position: absolute;
    left: 5px;
    top: -2px;
    border-top: 1px solid #fff;
    border-left: 1px solid #fff;
    z-index: 3;
    -webkit-transform: rotate(225deg);
    transform: rotate(225deg);
}
.hidden {
    display: none !important;
}

/*底部样式*/
.mod_foot_acitons {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 99;
    height: 48px;
    line-height: 48px;
    font-size: 14px;
    white-space: nowrap;
    border-top: 1px solid #CCC;
    background-color: #f9f9f9;
    box-sizing: border-box;
}
.foot_order_info2 {
    line-height: 16px;
}
.foot_order_info {
    position: relative;
    z-index: 2;
    display: table;
    table-layout: fixed;
    width: 100%;
    height: 100%;
    color: #ff7d13;
    white-space: nowrap;
    word-wrap: normal;
}
.foot_order_info2 .item {
    vertical-align: top;
}
.foot_order_info .item_col1 {
    padding-left: 15px;
}
.foot_order_info .item {
    display: table-cell;
    vertical-align: middle;
}
.foot_order_info .loading_ico, .mod_order_info .loading_ico {
    width: 25px;
    height: 25px;
    background-position: 0 0;
}
.loading_ico {
    width: 25px;
    height: 25px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    -webkit-animation: forward_loading 1.58s linear infinite;
    -moz-animation: forward_loading 1.58s linear infinite;
    -ms-animation: forward_loading 1.58s linear infinite;
    animation: forward_loading 1.58s linear infinite;
    transform-origin: 50% 50%;
    -webkit-transform-origin: 50% 50%;
    -moz-transform-origin: 50% 50%;
    -ms-transform-origin: 50% 50%;
    background: url(https://pic.c-ctrip.com/h5/group_travel/loading_orange.png) 0 0;
    background-size: 25px 25px;
}
.foot_order_info2 .item_col2 {
    width: 85px;
}
.foot_order_info2 .item_col3 {
    width: 85px;
}
.mod_foot_acitons .btn_link4 {
    display: block;
    height: 48px;
    line-height: 30px;
    font-size: 16px;
    color: #333;
    text-align: center;
    border-left: 1px solid #DDD;
    background-color: #FFF;
}
.mod_foot_acitons .btn_link4 span, .mod_foot_acitons .btn_link5 span {
    display: block;
    min-width: 64px;
    width: 64px;
    font-size: 12px;
    line-height: 16px;
    text-align: left;
    margin: -4px auto 0;
}
.mod_foot_acitons .btn_link5 {
    line-height: 30px;
}
.mod_foot_acitons .btn_link, .mod_foot_acitons .btn_link2, .mod_foot_acitons .btn_link3, .mod_foot_acitons .btn_link5 {
    display: block;
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    text-align: center;
    color: #FFF;
    background-color: #ff9b00;
    position: relative;
    top: -1px;
}
.pkg_room_num .num_invalid {
    background: 0;
    color: #d9d9d9 !important;
}
.book{
    line-height: 48px;
    color: #fff;
    font-size: 16px;
    text-align: center;
}
.na_bottom {
    padding: 0px;
    background: #fff;
}
</style>